package com.janko.springbootbase.a_projectExample.no_transaction;

import com.janko.springbootbase.entity.BaseUser;
import com.janko.springbootbase.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author nyk
 * @Date 2021/7/1 11:33
 * @Version 1.0
 * @Desc 事务失效场景 添加了try catch之后
 */

@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
public class t1_trycatch {

    @Autowired
    UserMapper userMapper;


    @Rollback(false)// 不添加它的话  会插入DB不成功
    @Transactional()
    @Test
    public  void InsertDb(){
        BaseUser user=new BaseUser().setId(9).setName("99").setAddress("北京");
        Integer result=  userMapper.insert(user);
        System.out.println(result);
    }
}
